package com.newtouch.krd_app.view;

import android.content.Context;
import android.view.View;

import com.newtouch.krd_app.http.api.TerminalApi;
import com.newtouch.krd_app.util.ControllerInterface;

import java.util.Timer;
import java.util.TimerTask;

/**
 * author : TQ
 * time   : 2023/2/14
 * desc   : 组件基类
 */
public class WidgetView {

    Context context;
    protected View view;
    private TerminalApi.Bean.FilesDTO filesDTO;

    protected Timer timer;
    protected TimerTask timerTask;
    protected ControllerInterface controllerInterface;

    /**
     * 构造函数
     * @param context as
     */
    public WidgetView(Context context)
    {
        this.context = context;
        initView();

    }

    public WidgetView(Context context, ControllerInterface controllerInterface)
    {
        this.controllerInterface = controllerInterface;
        this.context = context;
        initView();

    }

    /**
     * 创建控件
     */
    public View initView() {
        return view;
    }

    /**
     * 开始进行播放
     */
    public void startPlay() {

    }

    /**
     * 停止播放并释放资源
     */
    public void terminatePlay(){
        if (timer !=null) {
            timer.cancel();
            timer = null;
        }
        if (timerTask !=null) timerTask.cancel();
        timerTask = null;
    }
    /**
     * 停止播放
     */
    public void stopPlay(){
        if (timer !=null) {
            timer.cancel();
            timer = null;
        }
        if (timerTask !=null) timerTask.cancel();
        timerTask = null;
    }

    public View getView() {
        return view;
    }

    public TerminalApi.Bean.FilesDTO getFilesDTO() {
        return filesDTO;
    }

    /**
     * 设置播放文件数据，
     * @param filesDTO
     */
    public void setFilesDTO(TerminalApi.Bean.FilesDTO filesDTO) {
        this.filesDTO = filesDTO;
    }

    /**
     * 获取当前文件播放时长，子类实现
     * @return
     */
    public int getDuration(){
        return 0;
    }
}
